/*
 * Programmed By: Jimmy Blanchard
 * Programmed On: April 12, 2010
 * Last Modified: April 12, 2010
 * Package:       org.apcs.pokemon.audio
 * Filename:      Audio.java
 * Description:   Creates an audio thread and parses requests.
 *
 * Notes: Basic framework done, left vague for audio guys to fine tune to their requirements.
 *  - Really doesn't need dedicated thread, just used to prevent lag when loading audio file.
 */

package org.apcs.pokemon.audio;

import sun.audio.*;
import java.io.*;

public class Audio {
    public Audio(){
        new audioThread().start();
    }

    /*
     * Play an audiofile
     *
     * @param rawFileName Desired Audio File
     */
    public Audio(String rawFileName){
        new audioThread("src/org/apcs/pokemon/audio/"+rawFileName).start();
    }

    //Main audio thread
    private class audioThread extends Thread{
        private String filename;

        protected audioThread(){
            filename = "src/org/apcs/pokemon/audio/no_audio.wav";
        }

        protected audioThread(String rawFileNameThread){
            filename = rawFileNameThread;
        }

        @Override
        public void run(){
            try {
                InputStream in = new FileInputStream(filename);
                AudioStream as = new AudioStream(in);
                AudioPlayer.player.start(as);
            } catch (Exception e){
                System.out.println(e);
            }
        }
    }
}
